home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / falcon / programm.ing / nt_dsp1.lzh / NT_DSP1.MSA / FNTNS / LOG2NRM.ASM < prev    next >
Assembly Source File  |  1989-01-24  |  2KB  |  63 lines

  1. ;
  2. ; This program originally available on the Motorola DSP bulletin board.
  3. ; It is provided under a DISCLAMER OF WARRANTY available from
  4. ; Motorola DSP Operation, 6501 Wm. Cannon Drive W., Austin, Tx., 78735.
  5. ; Normalizing Base 2 Logarithm Macro
  6. ; Last Update 30 Mar 87   Version 1.0
  7. ;
  8. log2nrm macro
  9. log2nrm ident   1,0
  10. ;
  11. ;       This program calculates the base 2 logarithm of an unnormalized
  12. ;       24 bit fraction "x" in register A and returns a scaled fraction
  13. ;       "y" in register A.
  14. ;
  15. ;       y = log2(x)/32.0        where   2**(-23) =< x < 1.0
  16. ;                                       -23/32 =< y < 0.0
  17. ;
  18. ;       Note - "x" must be a non-zero, positive fraction.
  19. ;
  20. ;       Three steps are required.
  21. ;
  22. ;       1. Normalize "x" so that 0.5 =< A < 1.0.
  23. ;       2. Calculate the log2(A).
  24. ;       3. Divide the result by 32.0
  25. ;
  26. ;
  27. ;       Step 1 - Normalize A to get value between .5 and 1.0
  28. ;
  29.         move    #-1,m1          ;linear addressing
  30.         move    m1,m7
  31.         move    m7,r7           ;initial count = -1
  32.         rep     #23             ;normalize to between .5 and 1.0
  33.         norm    r7,a            ;shift left and decrement r7 if needed
  34.         move    #pcoef,r1       ;point to polynomial coefficients for log2
  35.         move    a,x0            ;put normalized number in x0
  36. ;
  37. ;       Step 2 - Calculate LOG2 by polynomial approximation.  8 Bit accuracy.
  38. ;
  39. ;       LOG2(x) = 4.0* (-.3372223 x*x + .9981958 x - .6626105)
  40. ;                           a2             a1            a0
  41. ;       where  0.5 <= x < 1.0
  42. ;
  43. ;       r1 initially points to the coefficients in y memory in the
  44. ;       order: a1,a2,a0
  45. ;
  46.         mpyr    x0,x0,a  y:(r1)+,y0     ;x**2, get a1
  47.         mpy     x0,y0,a  a,x1 y:(r1)+,y0        ;a1*x, mv x**2, get a2
  48.         mac     x1,y0,a  y:(r1)+,y0     ;a2* x**2, get a0
  49.         add     y0,a                    ;add in a0
  50.         asl     a                       ;multiply by 4
  51.         asl     a
  52. ;
  53. ;       Step 3 - Divide result by 32.
  54. ;
  55.         asl     a                       ;shift out sign bit
  56.         move    r7,a2                   ;new sign = characteristic
  57.         rep     #6                      ;divide by 32, create sign bit
  58.         asr     a
  59.         rnd     a                       ;round result
  60.         endm
  61.